using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class ChoosePeoplePage : BasePage
	{
		public enum ChoosePeoplePageFrom
		{
			MassSend,
			SnsSharePhoto
		}
		private const string TAG = "ChoosePeoplePage";
		private List<Contact> filterConList;
		private List<string> filterNameList;
		private ChoosePeoplePage.ChoosePeoplePageFrom fromType;
		public ContactCheckDone ContactListDoneCallBack;
		private ApplicationBar mBar;
		private ApplicationBarIconButton SelectAllBtn;
		private ApplicationBarIconButton OkMenuBtn;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal Grid ContentPanel;
		internal ContactsView mContactView;
		private bool _contentLoaded;
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && Enumerable.Count<object>(object_0) >= 2)
			{
				this.fromType = (ChoosePeoplePage.ChoosePeoplePageFrom)object_0[0];
				this.ContactListDoneCallBack = (object_0[1] as ContactCheckDone);
				if (Enumerable.Count<object>(object_0) == 3)
				{
					this.filterConList = (object_0[2] as List<Contact>);
					if (this.filterConList == null)
					{
						return;
					}
					this.filterNameList = new List<string>();
					for (int i = 0; i < this.filterConList.get_Count(); i++)
					{
						this.filterNameList.Add(this.filterConList.get_Item(i).strUsrName);
					}
				}
			}
		}
		public ChoosePeoplePage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ChoosePeoplePage_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ChoosePeoplePage_Unloaded));
		}
		private void ChoosePeoplePage_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.fromType == ChoosePeoplePage.ChoosePeoplePageFrom.SnsSharePhoto)
			{
				base.set_ApplicationBar(this.GetOneIconAppBar());
			}
			else
			{
				base.set_ApplicationBar(this.GetApplicationBar());
			}
			if (this.filterNameList != null)
			{
				ContactsView.resetCheckedList(this.filterNameList);
				return;
			}
			ContactsView.resetCheckedList();
		}
		private void ChoosePeoplePage_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private ApplicationBar GetOneIconAppBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.OkMenuBtn = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.OkMenuBtn.set_Text(strings.COM_Confirm);
			this.OkMenuBtn.add_Click(new EventHandler(this.OkMenuBtn_Click));
			this.OkMenuBtn.set_IsEnabled(false);
			this.mBar.get_Buttons().Add(this.OkMenuBtn);
			return this.mBar;
		}
		private ApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.SelectAllBtn = new ApplicationBarIconButton(new Uri("/Source/Plugin/MassSend/Resource/Img/MassSend_AllSelect.png", 2));
			this.SelectAllBtn.set_Text(strings.MassSend_SelectAll);
			this.SelectAllBtn.add_Click(new EventHandler(this.SelectAllBtn_Click));
			this.mBar.get_Buttons().Add(this.SelectAllBtn);
			this.OkMenuBtn = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.OkMenuBtn.set_Text(strings.COM_Confirm);
			this.OkMenuBtn.add_Click(new EventHandler(this.OkMenuBtn_Click));
			this.OkMenuBtn.set_IsEnabled(false);
			this.mBar.get_Buttons().Add(this.OkMenuBtn);
			return this.mBar;
		}
		private void OkMenuBtn_Click(object sender, EventArgs e)
		{
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			if (checkedItem == null || checkedItem.get_Count() <= 0)
			{
				MessageBoxManager.ShowToast(strings.ChatAddPeopleSelectAlert, 2500, null, false);
				return;
			}
			if (this.fromType == ChoosePeoplePage.ChoosePeoplePageFrom.MassSend)
			{
				string text = "";
				for (int i = 0; i < checkedItem.get_Count() - 1; i++)
				{
					if (!(checkedItem.get_Item(i).strUsrName == AccountMgr.getCurAccount().strUsrName))
					{
						text += checkedItem.get_Item(i).strUsrName;
						text += ";";
					}
				}
				text += checkedItem.get_Item(checkedItem.get_Count() - 1).strUsrName;
				base.GoToPage("/Source/Plugin/MassSend/UI/SendMessagePage.xaml", new object[]
				{
					text,
					(uint)checkedItem.get_Count(),
					false
				}, true);
				return;
			}
			if (this.ContactListDoneCallBack != null)
			{
				this.ContactListDoneCallBack(checkedItem);
			}
			base.GoBack();
		}
		private void SelectAllBtn_Click(object sender, EventArgs e)
		{
			if (this.SelectAllBtn.get_Text() == strings.MassSend_SelectAll)
			{
				this.SelectAllBtn.set_Text(strings.COM_Cancel);
				this.SelectAllBtn.set_IconUri(new Uri("/Source/Plugin/MassSend/Resource/Img/MassSend_NoSelect.png", 2));
				this.mContactView.CheckAllContacts();
			}
			else
			{
				this.SelectAllBtn.set_Text(strings.MassSend_SelectAll);
				this.SelectAllBtn.set_IconUri(new Uri("/Source/Plugin/MassSend/Resource/Img/MassSend_AllSelect.png", 2));
				ContactsView.UnCheckAllContacts();
			}
			this.CheckItemChange();
		}
		private void ItemCheckChanged(object sender, object object_0)
		{
			this.CheckItemChange();
		}
		private void CheckItemChange()
		{
			List<Contact> checkedItem = ContactsView.getCheckedItem();
			if (checkedItem.get_Count() == 0)
			{
				this.OkMenuBtn.set_IsEnabled(false);
				return;
			}
			this.OkMenuBtn.set_IsEnabled(true);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/MassSend/UI/ChoosePeoplePage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.mContactView = (ContactsView)base.FindName("mContactView");
		}
	}
}
